package org.wjk.pojo.vo;

import lombok.Data;
import lombok.experimental.Accessors;
import org.wjk.exception.FailureMsg;

@Data
@Accessors(chain = true)
public class ResponseRes {
    private final Integer resCode;/*指定任务成功还是失败的状态码*/
    private final String resMsg;//响应的信息，制定了业务执行成功还是失败时页面上需要显示的消息
    private final Object resData;//制定了业务执行后需要相应给前端的数据

    private ResponseRes(Integer resCode,String resMsg,Object resData){
        this.resCode=resCode;
        this.resMsg=resMsg;
        this.resData=resData;
    }
    //业务执行成功的响应函数
    public static ResponseRes success(String resMsg){
        return new ResponseRes(2000,resMsg,null);
    }
    public static ResponseRes success(String resMsg,Object resData){
        return new ResponseRes(2000,resMsg,resData);
    }
    //业务失败的响应
    public static ResponseRes failure(Integer resCode,String resMsg,Object resData){
        return new ResponseRes(resCode,resMsg,resData);
    }
    public static ResponseRes failure(FailureMsg failureMsg,Object resData){
        return new ResponseRes(failureMsg.getResCode(),failureMsg.getResMsg(),resData);
    }
    public static ResponseRes failure(FailureMsg failureMsg){
        return new ResponseRes(failureMsg.getResCode(),failureMsg.getResMsg(),null);
    }

}
